<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2019/1/11
 * Time: 16:38
 */

namespace app\sports_admin\controller;
use think\Request;
use app\sports_admin\model\Sport as sportModel;
use app\exception\SportException;

class Sport extends Base
{
    //运动类型
    public function index()
    {
        return view('index');
    }
    //运动类型 列表
    public function sportList()
    {
        $params = Request::instance()->only(['page','rows','sort','sortOrder']);
        $page = intval($params['page']) ? intval($params['page']) : 1;
        $rows = intval($params['rows']) ? intval($params['rows']) : 15;
        $sort = trim($params['sort']) ? trim($params['sort']) : 'id';
        $sortOrder = trim($params['sortOrder']) ? trim($params['sortOrder']) : 'asc';
        $result = sportModel::sportList($page,$rows,$sort,$sortOrder);
        return json($result);
    }
    //运动类型 删除
    public function del(Request $request)
    {
        if($request->isAjax())
        {
            $data = sportModel::del();
            if(!$data){
                throw new SportException([
                    'msg'=>'删除失败',
                    'errorCode'=>400
                ]);
            }
            return json(['code'=>202,'msg'=>'删除成功']);
        }
    }
    //运动类型 添加
    public function add(Request $request)
    {
        if($request->isAjax()){
            $data = sportModel::add();
            if(!$data){
                throw new SportException([
                    'msg'=>'添加失败',
                    'errorCode'=>400
                ]);
            }
            return json(['code'=>200,'msg'=>'添加成功']);
        }
    }



}